package cn.choujay.tlias.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Aspect
public class AopTest {

    @Pointcut("execution(* cn.choujay.tlias.service.*.*(..))")
    public void pt() {

    }

    //前置通知
    @Before("pt()")
    public void before(JoinPoint joinPoint) {
        log.info("Before.....{}", joinPoint);
    }

    //环绕通知
    @Around("pt()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        log.info("around Before.....");
        Object proceed = proceedingJoinPoint.proceed();
        log.info("around After.....");
        //返回的值就是方法执行后的返回的值
        return proceed;
    }

    //后置通知
    @After("pt()")
    public void after(JoinPoint joinPoint) {
        log.info("after......{}", joinPoint);
    }

    //返回后通知 程序在正常执行的情况下，会执行的后置通知
    @AfterReturning("pt()")
    public void afterReturning(JoinPoint joinPoint) {
        log.info("afterReturning.......{}", joinPoint);
    }

    //异常的通知 程序在出现异常的情况下，执行的后置通知
    @AfterThrowing("pt()")
    public void afterThrowing(JoinPoint joinPoint) {
        log.info("afterThrowing.......{}", joinPoint);
    }
    /*
     *
     *  around Before.....
     *  Before.....execution(List cn.choujay.tlias.service.impl.EmpServiceImpl.getAllEmp())
     *  afterReturning.......execution(List cn.choujay.tlias.service.impl.EmpServiceImpl.getAllEmp())
     *  after......execution(List cn.choujay.tlias.service.impl.EmpServiceImpl.getAllEmp())
     *  around After.....
     */
}
